home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / ENTRPRIS / APE / AEPOOL / MODPOOL.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-12-06  |  25.5 KB  |  561 lines

  1. Attribute VB_Name = "modPoolMgr"
  2. Option Explicit
  3. 'Declarations
  4. Declare Function GetTickCount Lib "kernel32" () As Long
  5.  
  6.  
  7.  
  8. 'Constants
  9. Public Const gbSHOW_FORM_DEFAULT As Boolean = False
  10. Public Const gbLOG_DEFAULT As Boolean = False
  11. Public Const glWORKER_QUANTITY_DEFAULT As Long = 1
  12. Public Const glLIST_BOX_MAX As Long = 500
  13. Public Const giMAX_ALLOWED_RETRIES = 500
  14. Public Const giRETRY_WAIT_MIN  As Integer = 500       'Retry Wait is measure in DoEvent cycles
  15. Public Const giRETRY_WAIT_MAX  As Integer = 2500
  16. Public Const gsPROTOCOL_DEFAULT As String = "ncacn_ip_tcp"
  17. Public Const glAUTHENTICATION_DEFAULT As Long = 1
  18. Public Const giWORKER_QUANTITY_DEFAULT As Integer = 1
  19. Public Const gbWORKER_EARLYBIND_DEFAULT As Integer = True
  20. Public Const giERROR_THRESHOLD As Integer = 32700
  21. Public Const glMAX_LONG As Long = 2147483647
  22.  
  23. 'User Defined Errors which also serve as string
  24. 'resource indexes
  25. Public Const giNO_WORKERS_CREATED As Integer = 32764
  26. Public Const giINVALID_PARAMETER As Integer = 32765
  27. Public Const giCONNECTION_SETTING_FAILED As Integer = 32750     'An error was returned by RacReg32
  28.  
  29. 'String resourse keys for logging messages
  30. Public Const giPOOL_NAME As Integer = 2
  31. Public Const giGET_WORKER As Integer = 3
  32. Public Const giRELEASE_WORKER As Integer = 4
  33. Public Const giCALL_REJECTED_RETRY As Integer = 11
  34. Public Const giUSING_NO_AUTHENTICATION As Integer = 12
  35. Public Const giONLY_N_WORKERS_CREATED As Integer = 13
  36. Public Const giCOULD_NOT_CREATE_WORKER_ON_MACHINE As Integer = 14
  37. Public Const giALL_WORKERS_CREATED As Integer = 15
  38. Public Const giCOULD_NOT_CREATE_LOCAL_WORKER As Integer = 16
  39. Public Const giERROR_PREFIX As Integer = 17
  40.  
  41. Public Const giFONT_CHARSET_INDEX As Integer = 30
  42. Public Const giFONT_NAME_INDEX As Integer = 31
  43. Public Const giFONT_SIZE_INDEX  As Integer = 32
  44.  
  45. 'String resource keys for Form captions
  46. Public Const giLBL_SATISFIED As Integer = 50
  47. Public Const giLBL_REJECTED As Integer = 51
  48. Public Const giLBL_NUM_WORKERS As Integer = 52
  49. Public Const giPOOLMGR_CAPTION As Integer = 53
  50.  
  51. Public Const giRACREG_ERROR_CODE_OFFSET = 200               'Add offset to racreg32 error codes
  52.                                                             'to make corresponding resource string key
  53.  
  54. 'Public variables
  55. Public gcWorkers As Collection              'This is basically the pool of available workers
  56. Public gcWorkerMachines As Collection        'Collection of clsWorkerMachines objects used
  57.                                              'keep track of how many worker objects are on
  58.                                              'each remote worker machine.
  59. Public glInstances As Long                  'A count of the number of instances made of PoolMgr
  60. Public gbShow As Boolean                    'If true show PoolMgr form
  61. Public gbLog As Boolean                     'If True log PoolMgr Events
  62. Public goLogger As AELogger.Logger
  63. Public gbLogWorkers As Boolean      'Flag to track status of
  64.                                     'Worker property Log
  65. Public gbUnloading As Boolean       'Flag used by Class_terminate
  66. Public giWorkerCount As Integer              'Number of Worker instanciated, This can be different
  67.                                              'than gcWorkers.Count if a Worker in the collection
  68.                                              'is marked for removal it will not be included in giWorkerCount
  69. Public glLastKeyUsed As Long                 'Last key used to add a worker to gcWorkers
  70.                                              'It is necessary to use this because a the
  71.                                              'giWorkerCount can be decreased but the Worker
  72.                                              'not actually removed until it calls back after
  73.                                              'completing a Service request.  During this time
  74.                                              'WorkerQuantity can be called again to increase
  75.                                              'the Worker count.  Therefore, giWorkerCount is
  76.                                              'not reliable for generating unique keys
  77. Public gbPersistentServices As Boolean      'Flag keeps track of Worker
  78.                                             'property PersistentServices
  79.                                             'If true Workers keep reference to
  80.                                             'all Service objects used else they
  81.                                             'drop references after each use.
  82. Public gbEarlyBindServices As Boolean       'Flag to track status of
  83.                                             'Worker property EarlyBound
  84. Public gbStopTest As Boolean        'Stop Test flag, checked by many procedures
  85.                                     'that will discontinue their processes if true
  86. Public gsProtocol As String                 'Protocol sequence to use when connecting to Workers
  87. Public glAuthentication As Long             'Authentication level to use when connecting to Workers
  88. Public gbUseDCOM As Boolean                 'If true use DCOM to create workers instead of Remote Automation
  89. Public glRequestsSatisfied As Long
  90. Public glRequestsRejected As Long
  91.  
  92. Public Sub CountInitialize()
  93.     '-------------------------------------------------------------------------
  94.     'Purpose:   Keep track of number instances of PoolMgr and Pool
  95.     '           To be called by a public creatable class in its initialize
  96.     '           event. To keep track of how many public creatable objects
  97.     '           are initialized.  Initialize the PoolMgr application if
  98.     '           this is the first time it is called.
  99.     'Effects:
  100.     '           If this is the first instanciation
  101.     '           Put the PoolMgr in a "Ready" state.  Load  Workers
  102.     '           Set default properties, Show form and load logger if necessary.
  103.     '   [glInstances]
  104.     '           increments by one
  105.     '-------------------------------------------------------------------------
  106.     Dim i As Integer
  107.     Dim oWork As clsWorker                   'Object storing Workers and related informantion
  108.     Dim oWorkerMachine As clsWorkerMachines  'Object that stores how many
  109.                                              'Workers are on what machines
  110.     Dim sReturn As String           'Return of SetWorkersOnMachine function
  111.     
  112.     On Error GoTo CountInitializeError
  113.     
  114.     glInstances = glInstances + 1
  115.     If glInstances = 1 Then
  116.         App.OleServerBusyRaiseError = True
  117.         App.OleServerBusyTimeout = 10000
  118.         'Set default property values
  119.         gbShow = gbSHOW_FORM_DEFAULT
  120.         gbLog = gbLOG_DEFAULT
  121.         gsProtocol = gsPROTOCOL_DEFAULT
  122.         glAuthentication = glAUTHENTICATION_DEFAULT
  123.         gbEarlyBindServices = gbWORKER_EARLYBIND_DEFAULT
  124.         'Create Logger class object early so
  125.         'potential errors could be logged
  126.         If gbLog Then Set goLogger = New AELogger.Logger
  127.         'Create collection objects
  128.         Set gcWorkers = New Collection
  129.         Set gcWorkerMachines = New Collection
  130.         'Add an item to represent number of workers on the local machine
  131.         Set oWorkerMachine = New clsWorkerMachines
  132.         gcWorkerMachines.Add oWorkerMachine
  133.         'Load the default amount of workers and add
  134.         'them to the gcWorkers Collection
  135.         sReturn = SetWorkersOnMachine(False, "", giWORKER_QUANTITY_DEFAULT)
  136.         
  137.         'Only show the form if gbShow is true
  138.         If gbShow Then
  139.             With frmPoolMgr
  140.                 .Show
  141.                 .lblStatus.Caption = ""
  142.                 .lblWorkers.Caption = CStr(giWorkerCount)
  143.                 .lblSatisfied.Caption = 0
  144.                 .lblRejected.Caption = 0
  145.             End With
  146.         End If
  147.         gbUnloading = False
  148.     End If
  149.     Exit Sub
  150. CountInitializeError:
  151.     Select Case Err.Number
  152.         Case ERR_CANT_FIND_KEY_IN_REGISTRY
  153.             'AEInstancer.Instancer is a work around for error
  154.             '-2147221166 which occurrs every time a client
  155.             'object creates an instance of a remote server,
  156.             'destroys it, registers it local, and tries to
  157.             'create a local instance.  The client can not
  158.             'create an object registered locally after it created
  159.             'an instance while it was registered remotely
  160.             'until it shuts down and restarts.  Therefore,
  161.             'it works to call another process to create the
  162.             'local instance and pass it back.
  163.             Dim oInstancer As AEInstancer.Instancer
  164.             Set oInstancer = New AEInstancer.Instancer
  165.             Set goLogger = oInstancer.Object("AELogger.Logger")
  166.             Set oInstancer = Nothing
  167.             Resume Next
  168.         Case Else
  169.             LogError Err
  170.             Resume Next
  171.     End Select
  172. End Sub
  173.  
  174. Public Sub CountTerminate()
  175.     '-------------------------------------------------------------------------
  176.     'Purpose:   Keep track of number instances of PoolMgr and Pool
  177.     '           To be called by a public creatable class in its terminate
  178.     '           event. To keep track of how many public creatable objects
  179.     '           are initialized.  Terminate the PoolMgr application if
  180.     '           this is the last time called.
  181.     'Effects:
  182.     '           Unload all objects, and unload form so that this application
  183.     '           will close
  184.     '   [glInstances]
  185.     '           decrements by one
  186.     '-------------------------------------------------------------------------
  187.     Dim oWorker As clsWorker
  188.     On Error GoTo Class_TerminateError
  189.     glInstances = glInstances - 1
  190.     'If already started unloading don't check
  191.     'instance count again
  192.     If Not gbUnloading Then
  193.         If glInstances = 0 Then
  194.             gbUnloading = True
  195.             For Each oWorker In gcWorkers
  196.                 Set oWorker.Worker = Nothing
  197.                 Set oWorker = Nothing
  198.             Next
  199.             Set goLogger = Nothing
  200.             Set gcWorkers = Nothing
  201.             Set gcWorkerMachines = Nothing
  202.             giWorkerCount = 0
  203.             Unload frmPoolMgr
  204.         End If
  205.     End If
  206.     Exit Sub
  207. Class_TerminateError:
  208.     LogError Err
  209.     Resume Next
  210. End Sub
  211.  
  212. Public Sub LogEvent(intMessage As Integer)
  213.     'Receives Message key which is used to look
  214.     'up a resource string.  The logrecord is sent to the
  215.     'Logger object if gbLog is true
  216.     On Error GoTo LogEventError
  217.     If gbLog Then
  218.         goLogger.Record LoadResString(giPOOL_NAME), 0, LoadResString(intMessage), GetTickCount()
  219.     End If
  220.     #If ccShowList Then
  221.         'If the form is visible display log on form
  222.         If gbShow Then
  223.             DisplayString "0" & gsSEPERATOR & LoadResString(intMessage)
  224.         End If
  225.     #End If
  226.     Exit Sub
  227. LogEventError:
  228.     LogError Err
  229.     Exit Sub
  230. End Sub
  231.  
  232. Public Sub LogError(ByVal oErr As ErrObject)
  233.     'Display error on form with no user input required
  234.     'Log error if logging is on
  235.     Dim s As String
  236.     s = LoadResString(giERROR_PREFIX) & Str$(oErr.Number) & gsSEPERATOR & oErr.Source & gsSEPERATOR & oErr.Description
  237.     #If ccShowList Then
  238.         If Not gbShow Then
  239.             frmPoolMgr.Show
  240.             gbShow = True
  241.         End If
  242.         DisplayString s
  243.     #Else
  244.         DisplayStatus s
  245.     #End If
  246.     If gbLog And glInstances <> 0 Then
  247.         goLogger.Record LoadResString(giPOOL_NAME), 0, LoadResString(giERROR_PREFIX) & Str$(oErr.Number) & gsSEPERATOR & oErr.Source & gsSEPERATOR & oErr.Description, GetTickCount()
  248.     End If
  249. End Sub
  250.  
  251. Sub DisplayStatus(sText As String)
  252.     If gbShow Then frmPoolMgr.lblStatus = sText
  253. End Sub
  254.  
  255. Sub DisplayString(sText As String)
  256.     #If ccShowList Then
  257.         'Controls the length of the list box
  258.         'and sets ListIndex
  259.         Dim lstLog As ListBox
  260.         If gbShow Then
  261.             Set lstLog = frmPoolMgr.lstLog
  262.             If lstLog.ListCount = glLIST_BOX_MAX Then lstLog.Clear
  263.             lstLog.AddItem sText, 0
  264.         End If
  265.     #End If
  266. End Sub
  267.  
  268. Sub Main()
  269.  
  270. End Sub
  271.  
  272. Public Function SetWorkersOnMachine(bRemote As Boolean, sMachineName As String, lQuantityOnMachine As Long) As String
  273.     '-------------------------------------------------------------------------
  274.     'Purpose:   Sets the quantity of instanciated Workers on a particular machine
  275.     'IN:
  276.     '   [bRemote]
  277.     '           If true adjust number of workers on a remote machine; else,
  278.     '           adjust the number on the local machine.
  279.     '   [sMachineName]
  280.     '           Name of machine to adjust the level of instanciated Workers
  281.     '   [lQuantityOnMachine]
  282.     '           Number of Instantiated Workers that should be on specified
  283.     '           machine.
  284.     'Return:    Discription of Errors that should be displayed to user
  285.     'Effects:
  286.     '   [gcWorkers]
  287.     '           The number of Workers in this collection will be adjusted
  288.     '   [gcWorkerMachines]
  289.     '           An item may be added or removed or edited
  290.     '-------------------------------------------------------------------------
  291.     Dim oRacReg As RacReg.RegClass          'Object to set automation connection settings
  292.     Dim oWorkerMachine As clsWorkerMachines 'Object that stores how many workers are on
  293.                                             'a machine, retrieved from global collection
  294.     Dim oWorkerProvider As AEWorkerProvider.WorkerProvider  'Server that can be instanciated on remote
  295.                                                             'machines to provide Worker objects
  296.     Dim lWorkerToRemove As Long             'ID of Worker found to remove
  297.     Dim oWork As clsWorker                  'clsWorker object that hold reference to a Worker
  298.                                             'and information related to it
  299.     Dim lAdd As Long                        'New ID for New Worker
  300.     Dim sErrors As String                   'Discription of Errors that will be returned
  301.     Dim bAddingWorker As Boolean            'If true, adding and configuring worker
  302.                                             'used by error handling
  303.     
  304.     Dim iRetry As Integer                   'Error retry counter
  305.     Dim iResult As Integer                  'RacReg error code
  306.     
  307.     On Error GoTo SetWorkersOnMachineError
  308.     
  309.     'Validate lQuantityOnMachine
  310.     If lQuantityOnMachine < 0 Then lQuantityOnMachine = 0
  311.     
  312.     'Set registry for local or remote machine name
  313.     Set oRacReg = New RacReg.RegClass
  314.     If bRemote Then
  315.         If gbUseDCOM Then
  316.             iResult = oRacReg.SetDCOMServerSettings(True, "AEWorkerProvider.WorkerProvider", , sMachineName)
  317.         Else
  318.             iResult = oRacReg.SetAutoServerSettings(True, "AEWorkerProvider.WorkerProvider", , sMachineName, gsProtocol, glAuthentication)
  319.         End If
  320.     Else
  321.         'Make sure the Machine name string is zero length
  322.         sMachineName = ""
  323.         'Make sure AEWorker.Worker is registered for local instanciation
  324.         'Because Clients may have been run on this machine and may have
  325.         'left the connection settings remote if they did not unload properly
  326.         iResult = oRacReg.SetAutoServerSettings(False, "AEWorker.Worker")
  327.         
  328.     End If
  329.     If iResult <> 0 Then GoTo SetWorkersOnMachine_RacRegError
  330.     
  331.     'Get the clsWorkerMachines object to store information in
  332.     If Not bRemote Then
  333.         'it is definitely the first item in the collection
  334.         Set oWorkerMachine = gcWorkerMachines.Item(1)
  335.     Else
  336.         'if it is in the collection it is stored by a key
  337.         'equaling the machine name
  338.         'If error equals ERR_INVALID_PROCEDURE_CALL there
  339.         'are no Workers on specified machine and no clsWorkerMachines
  340.         'class object to represent them
  341.         On Error Resume Next
  342.         Set oWorkerMachine = gcWorkerMachines.Item(sMachineName)
  343.         If Err.Number = ERR_INVALID_PROCEDURE_CALL Then
  344.             On Error GoTo SetWorkersOnMachineError
  345.             'Don't create a new clsWorkerMachine object of
  346.             'lQuantityOnMachine is zero
  347.             If lQuantityOnMachine <= 0 Then Exit Function
  348.             Set oWorkerMachine = New clsWorkerMachines
  349.             'If an error occurs creating WorkerProvider the current machine name
  350.             'can not be used.  Treat error as if a Worker can not be created on
  351.             'paticular machine.
  352.             bAddingWorker = True
  353.             Set oWorkerMachine.WorkerProvider = New AEWorkerProvider.WorkerProvider
  354.             bAddingWorker = False
  355.             
  356.             gcWorkerMachines.Add oWorkerMachine, sMachineName
  357.             With oWorkerMachine
  358.                 .Remote = True
  359.                 .MachineName = sMachineName
  360.             End With
  361.         End If
  362.         On Error GoTo SetWorkersOnMachineError
  363.         Set oWorkerProvider = oWorkerMachine.WorkerProvider
  364.     End If
  365.     
  366.     'Now see if more workers need destroyed on this machine
  367.     With oWorkerMachine
  368.         If .WorkerKeys.Count > lQuantityOnMachine Then
  369.             Do Until .WorkerKeys.Count <= lQuantityOnMachine
  370.                 'Find a worker on this machine
  371.                 lWorkerToRemove = .WorkerKeys.Item(1)
  372.                 .WorkerKeys.Remove 1
  373.                 'Remove the found worker
  374.                 'Do not destroy the Worker if it is busy
  375.                 'instead just flip its RemoveMe flag
  376.                 giWorkerCount = giWorkerCount - 1
  377.                 If gcWorkers.Item(CStr(lWorkerToRemove)).Busy Then
  378.                     gcWorkers.Item(CStr(lWorkerToRemove)).RemoveMe = True
  379.                 Else
  380.                     iRetry = 0
  381.                     gcWorkers.Item(CStr(lWorkerToRemove)).Worker.ShutDown
  382.                     Set gcWorkers.Item(CStr(lWorkerToRemove)).Worker = Nothing
  383.                     gcWorkers.Remove CStr(lWorkerToRemove)
  384.                 End If
  385.             Loop
  386.         Else
  387.             'Else lQuantityOnMachine must be greater than .WorkerKeys.count
  388.             'So add to the collection
  389.             bAddingWorker = True
  390.             Do Until .WorkerKeys.Count = lQuantityOnMachine
  391.                 'Choose a unique key
  392.                 lAdd = glLastKeyUsed + 1
  393.                 glLastKeyUsed = lAdd
  394.                 Set oWork = New clsWorker
  395.                 oWork.Busy = False
  396.                 oWork.ID = lAdd
  397.                 'Get a new Worker object
  398.                 If bRemote Then
  399.                     Set oWork.Worker = oWorkerProvider.GetWorker
  400.                 Else
  401.                     Set oWork.Worker = New AEWorker.Worker
  402.                 End If
  403.                 'Set the WorkerID property of AEWorker.Worker
  404.                 'Set the new worker property to the properties
  405.                 'that have been set for the any other workers
  406.                 iRetry = 0
  407.                 oWork.Worker.SetProperties gbLogWorkers, gbEarlyBindServices, _
  408.                         gbPersistentServices, lAdd
  409.                 'Add the clsWorker class object which holds a
  410.                 'reference to the Worker class object to gcWorkers collection
  411.                 'Use the WorkerID as the key
  412.                 gcWorkers.Add oWork, CStr(lAdd)
  413.                 giWorkerCount = giWorkerCount + 1
  414.                 .WorkerKeys.Add lAdd
  415.                 iRetry = 0
  416.             Loop
  417.             bAddingWorker = False
  418.         End If
  419.     End With
  420. SetWorkersOnMachineEnd:
  421.     'Update the WorkerCount label in the U/I
  422.     'Set connection settings back to local
  423.     iResult = oRacReg.SetAutoServerSettings(False, "AEWorkerProvider.WorkerProvider")
  424.     If iResult <> 0 Then GoTo SetWorkersOnMachine_RacRegError
  425.     
  426.     If gbShow Then
  427.         With frmPoolMgr.lblWorkers
  428.             .Caption = gcWorkers.Count
  429.             .Refresh
  430.         End With
  431.     End If
  432.     
  433.     'If the WorkerKeys.count = 0 and bRemote is true
  434.     'then the clsWorkerMachines class
  435.     'object in gcWorkerMachines should be removed
  436.     'Don't remove the clsWorkerMachines object representing the
  437.     'local machine.  Index one is reserved for the local machine.
  438.     If oWorkerMachine.WorkerKeys.Count = 0 And bRemote Then
  439.         On Error Resume Next
  440.         gcWorkerMachines.Remove sMachineName
  441.     End If
  442.     SetWorkersOnMachine = sErrors
  443.     Exit Function
  444. SetWorkersOnMachine_RacRegError:
  445.     Err.Raise giCONNECTION_SETTING_FAILED
  446. SetWorkersOnMachineError:
  447.     Select Case Err.Number
  448.         Case RPC_E_CALL_REJECTED
  449.             'Collision error, the OLE server is busy
  450.             Dim il As Integer
  451.             Dim ir As Integer
  452.             'First check for stop test
  453.             If iRetry < giMAX_ALLOWED_RETRIES Then
  454.                 iRetry = iRetry + 1
  455.                 ir = Int((giRETRY_WAIT_MAX - giRETRY_WAIT_MIN + 1) * Rnd + giRETRY_WAIT_MIN)
  456.                 For il = 0 To ir
  457.                     DoEvents
  458.                 Next il
  459.                 LogEvent giCALL_REJECTED_RETRY
  460.                 Resume
  461.             Else
  462.                 'We reached our max retries
  463.                 GoTo SetWorkersOnMachineUnexpectedError
  464.             End If
  465.         Case ERR_CANT_FIND_KEY_IN_REGISTRY
  466.             'AEInstancer.Instancer is a work around for error
  467.             '-2147221166 which occurrs every time a client
  468.             'object creates an instance of a remote server,
  469.             'destroys it, registers it local, and tries to
  470.             'create a local instance.  The client can not
  471.             'create an object registered locally after it created
  472.             'an instance while it was registered remotely
  473.             'until it shuts down and restarts.  Therefore,
  474.             'it works to call another process to create the
  475.             'local instance and pass it back.
  476.             Dim oInstancer As AEInstancer.Instancer
  477.             Set oInstancer = New AEInstancer.Instancer
  478.             Set oWorkerProvider = oInstancer.Object("AEWorkerProvider.WorkerProvider")
  479.             Set oInstancer = Nothing
  480.             Resume Next
  481.         Case RPC_S_UNKNOWN_AUTHN_TYPE
  482.             'Tried to connect to a server that does not support
  483.             'specified authentication level.  Display message and
  484.             'switch to no authentication and try again
  485.             Dim s As String
  486.             s = ReplaceString(LoadResString(giUSING_NO_AUTHENTICATION), gsNAME_TOKEN, sMachineName)
  487.             LogText s
  488.             sErrors = s & vbCrLf
  489.             iResult = oRacReg.SetAutoServerSettings(True, "AEWorkerProvider.WorkerProvider", , sMachineName, gsProtocol, glAUTHENTICATION_DEFAULT)
  490.             Resume
  491.         Case ERR_OVER_FLOW
  492.             glLastKeyUsed = 0
  493.             Resume
  494.         Case ERR_DUPLICATE_KEY
  495.             'Assusmes on line "gcWorkers.Add oWork, cstr(lAdd)"
  496.             If lAdd = glMAX_LONG Then lAdd = 0 Else lAdd = lAdd + 1
  497.             glLastKeyUsed = lAdd
  498.             oWork.ID = lAdd
  499.             Resume
  500.         Case giCONNECTION_SETTING_FAILED
  501.             sErrors = ReplaceString(LoadResString(giCONNECTION_SETTING_FAILED), gsNAME_TOKEN, LoadResString(giRACREG_ERROR_CODE_OFFSET + iResult))
  502.             Err.Raise giNO_WORKERS_CREATED, , sErrors & vbCrLf & LoadResString(giNO_WORKERS_CREATED)
  503.         Case Else
  504. SetWorkersOnMachineUnexpectedError:
  505.             'There are three cases to respond to if there is an unexpected error
  506.             '1- If the error occured while NOT adding a worker it most likely
  507.             '   occured while removing one.  Resume Next to insure that the worker
  508.             '   is removed from the workers collection.
  509.             '2- If we were adding a worker and the worker class was registered local
  510.             '   log the error, and add it to the sError string, but raise the
  511.             '   giNO_WORKERS_CREATED error, because the system has a critical problem
  512.             '   if a local worker can not be created.
  513.             '3- If we were adding a worker and the worker class was registered remote
  514.             '   log the error, and add it to the sError string.  Exit procedure so
  515.             '   that calling procedure can try creating workers on another machine
  516.             Dim sSource As String
  517.             sSource = Err.Source
  518.             sErrors = sErrors & sMachineName & gsSEPERATOR & sSource & gsSEPERATOR & Err.Description & vbCrLf
  519.             LogError Err
  520.             If Not bAddingWorker Then
  521.                 Resume Next
  522.             Else
  523.                 If bRemote Then
  524.                     sErrors = sErrors & vbCrLf & ReplaceString(LoadResString(giCOULD_NOT_CREATE_WORKER_ON_MACHINE), gsNAME_TOKEN, sMachineName)
  525.                     Resume SetWorkersOnMachineEnd
  526.                 Else
  527.                     iResult = oRacReg.SetAutoServerSettings(False, "AEWorkerProvider.WorkerProvider")
  528.                     sErrors = sErrors & vbCrLf & LoadResString(giCOULD_NOT_CREATE_LOCAL_WORKER)
  529.                     Err.Raise giNO_WORKERS_CREATED, sSource, sErrors & vbCrLf & LoadResString(giNO_WORKERS_CREATED)
  530.                 End If
  531.             End If
  532.     End Select
  533. End Function
  534.  
  535. Public Sub LogText(sMsg As String)
  536.     '-------------------------------------------------------------------------
  537.     'Purpose:   Passes that passed string as a log record
  538.     '           to the logger
  539.     'In:        [sMsg]
  540.     '               String to be logged
  541.     '           [lServiceID]
  542.     '               Service Request ID to be logged
  543.     'Assumption:
  544.     '           If gbLog is true then goLogger is a valid reference to
  545.     '           AELogger.Logger class object
  546.     '-------------------------------------------------------------------------
  547.     On Error GoTo LogTextError
  548.     If gbLog And Not gbStopTest Then
  549.         goLogger.Record LoadResString(giPOOL_NAME), 0, sMsg, GetTickCount()
  550.     End If
  551.     'If the form is visible display log on form
  552.     #If ccShowList Then
  553.         DisplayString CStr(lServiceID) & gsSEPERATOR & sMsg
  554.     #End If
  555.     Exit Sub
  556. LogTextError:
  557.     LogError Err
  558.     Exit Sub
  559. End Sub
  560.  
  561.